package com.jacky.javase;

import java.io.File;

public class SearchFile {
    public static void main(String[] args) {
        File file = new File("E:\\2012\\ssm2012");
        int blankNum = 0;
        new SearchFile().search(file, blankNum);
    }
    public void search(File file, int blankNum) {
        while (true) {
            File[] files = file.listFiles();
            for (File file1 : files) {
                if (file1.isDirectory()){
                    for(int i=0;i<blankNum;i++){
                        System.out.print("  ");
                    }
                    System.out.println("目录："+file1.getName());
                    if (file1.listFiles().length == 0){
                        break;
                    }
                    blankNum++;
                    search(file1,blankNum);
                    blankNum--;
                }
                else {
                    for(int i=0;i<blankNum;i++){
                        System.out.print("  ");
                    }
                    System.out.println("文件："+file1.getName());
                }
            }
//            System.out.println("目录:"+file.getName()+" *****遍历完成*****");
            blankNum--;
            break;
        }
    }
}
